#include "swagme.h"
#include "TouchableObject.h"

TouchableObject::TouchableObject()
{
  box.x = 0.0; box.y = 0.0; box.w = 0.0; box.h = 0.0;
}

TouchableObject::TouchableObject(int left, int top, int width, int height)
{
  box.x = left; box.y = top; box.w = width; box.h = height;
}

// Returns true if touchable is within 3 cells of this
const bool TouchableObject::isNear(const TouchableObject *touchable) {
  return isNear(touchable, TO_NEAR);
}

// Returns true if touchable is within the number of cells specified by nearness
const bool TouchableObject::isNear(const TouchableObject *touchable, const int nearness) {
  const int tx = (int)touchable->getLeft();
  const int ty = (int)touchable->getTop();
  // note that min & max values may be negative or outside the bounds of the map, that's okay because they're signed & not returned nor used to access the map
  const int minx = (int)box.x - nearness;
  const int maxx = (int)box.x + (int)box.w + nearness;
  const int miny = (int)box.y - nearness;
  const int maxy = (int)box.y + (int)box.h + nearness;

  // imagine a box around this object, we compare tx,ty to see if it's in the box
  if (((tx > minx) && (tx < maxx)) && ((ty > miny) && (ty < maxy))) {
    return true;
  }
  return false;
}